# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Anatol Pomozov <anatol dot pomozov at gmail>
# Contributor: Stéphane Gaudreault <stephane@archlinux.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org
#  - only use valgrind with v7/v8
#  - remove make/optdepend on cude and configure option

pkgname=openmpi
pkgver=4.0.5
pkgrel=3
pkgdesc='High performance message passing library (MPI)'
url='https://www.open-mpi.org'
arch=('x86_64')
license=('custom:OpenMPI')
depends=('glibc' 'libltdl' 'hwloc' 'openssh' 'zlib' 'libnl' 'perl' 'libevent')
makedepends=('inetutils' 'gcc-fortran')
makedepends_armv7h=('valgrind')
makedepends_aarch64=('valgrind')
optdepends=('gcc-fortran: fortran support')
options=('staticlibs')
source=(https://www.open-mpi.org/software/ompi/v${pkgver%.*}/downloads/${pkgname}-${pkgver}.tar.bz2)
sha256sums=('c58f3863b61d944231077f344fe6b4b8fbb83f3d1bc93ab74640bf3e5acac009')
b2sums=('9709dc8c251d4f2be14d0ab498c5d0d0e59f95db98fb16d9e84fe3d30af5a8e2f9636bbceaf7ae4086a3312bcd6299f0e9e1ca609d658930a1f5abe1018311e1')

build() {
  cd ${pkgname}-${pkgver}

   # enable valgrind and memchecker for v7/v8
   [[ $CARCH == "armv7h" || $CARCH == "aarch64" ]] && CONFIG='--with-valgrind --enable-memchecker'

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc/${pkgname} \
    --enable-mpi-fortran=all \
    --libdir=/usr/lib/${pkgname} \
    --enable-builtin-atomics \
    --enable-mpi-cxx \
    --enable-pretty-print-stacktrace \
    --without-slurm \
    --with-hwloc=/usr \
    --with-libltdl=/usr  \
    --with-libevent=/usr  \
    FC=/usr/bin/gfortran \
    LDFLAGS="${LDFLAGS} -Wl,-z,noexecstack" \
    $CONFIG
  make
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR="${pkgdir}" install

  # FS#28583
  install -dm 755 "${pkgdir}/usr/lib/pkgconfig"
  for i in ompi-c.pc ompi-cxx.pc ompi-f77.pc ompi-f90.pc ompi.pc; do
    ln -sf "/usr/lib/openmpi/pkgconfig/${i}" "${pkgdir}/usr/lib/pkgconfig/"
  done

  install -dm 755 "${pkgdir}/etc/ld.so.conf.d"
  echo "/usr/lib/${pkgname}" > "${pkgdir}"/etc/ld.so.conf.d/${pkgname}.conf
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
